package com.jml.springsecurity.validate.code;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;


@RestController
public class ValidateCodeController {

	@Autowired
	private Map<String,ValidateCodeProcessor> validateCodeProcessor;

	@GetMapping("/code/{type}")
	public void createCode(@PathVariable String type,HttpServletRequest request, HttpServletResponse response)throws Exception {
		for (Map.Entry<String, ValidateCodeProcessor> entry : validateCodeProcessor.entrySet()) {
			System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue().getClass());
		}
		ValidateCodeProcessor validateCodeProcessor1= validateCodeProcessor.get(type+"ValidateCodeProcessor");
		validateCodeProcessor1.create(new ServletWebRequest(request,response));
	}
}
